package com.syc.ext;

import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 全局返回结果
 */
@Data
@Accessors(chain = true)
@Slf4j
public class Result<T> implements Serializable{
	private static final long serialVersionUID = -5759964467525426508L;

	/**
	 * 错误码
	 */
	private String code;

	/**
	 * 错误信息
	 */
	private String message;

	/**
	 * 返回数据
	 */
	private T data;

	public Result(){}

	public Result(String code, String msg){
		this.code = code;
		this.message = msg;
	}

	public Result(String code, String msg,T data){
		this.code = code;
		this.message = msg;
		this.data=data;
	}

	public Result(T data){
		super();
		this.code = "0";
		this.message = "success";
		this.data = data;
	}

	public static <T> Result<T> ok(){
		return new Result("0", "request success");
	}

	public static <T> Result<T> ok(T data){
		return new Result("0", "request success",data);
	}

	public static <T> Result<T> failed(){
		return new Result("500", "操作失败");
	}


}
